package org.pz.service.impl;

import org.pz.constants.RedisConstant;
import org.pz.entity.UserEntity;
import org.pz.mapper.RoleMapper;
import org.pz.mapper.UserMapper;
import org.pz.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private RoleMapper roleMapper;

    @Override
    @Cacheable(value = RedisConstant.CACHE_KEY_USER, key = "#root.targetClass + #root.method.name + #p0")
    public UserEntity findUserEntityByUsername(String username) {
        return userMapper.findUserByUserName(username);
    }

    @Override
    @Cacheable(value = RedisConstant.CACHE_KEY_USER, key = "#root.targetClass + #root.method.name + #p0")
    public List<String> findRolesByAsset(String asset) {
        return roleMapper.needRolesByAsset(asset);
    }
}
